
source("c:/tappelhans/uni/software/development/metvurst/strip/strip.R")
source("c:/tappelhans/uni/software/development/metvurst/strip/colList.R")

inpath <- "e:/kili_data/testing/overview/ki"
#inpath <- "/home/eikistations/ei_data_kilimanjaro/processing/plots/ki"
#inpath <- "c:/tappelhans/uni/marburg/lehre/2011/ws/r_course/presentations/06_exercise/data/"

## list all file in input path (and sub folders) justifying pattern definition
a <- list.files(inpath, recursive = T, pattern = "eat_ca05_cti05_0005.dat")
a <- grep("000rug", a, value = T)


## read all files into a list
y <- lapply(1:length(a), function(i) read.table(paste(inpath,a[i],sep="/"), 
                                                header = T, sep = ",", fill = T))

list <- lapply(seq(y), function(i) subset(y[[i]], y[[i]]$PlotId != ""))

t <- sapply(seq(list), function(i) list[[i]]$Ta_200)
rh <- sapply(seq(list), function(i) list[[i]]$rH_200)
datetime <- sapply(seq(list), function(i) list[[i]]$Datetime)
plot <- sapply(seq(list), function(i) list[[i]]$PlotId)

## rbind all list entries
t <- unlist(t)
t <- ifelse(t > 50, NA, t)
t <- ifelse(t < 5, NA, t)
rh <- unlist(rh)
#print(head(t))
datetime <- unlist(datetime)
plot <- unlist(plot)
plot <- substr(plot, 5, 8)

plotname <- paste("overview", "rug_t", Sys.Date(), "wide", sep = "_")
plotname <- paste(plotname, ".png", sep = "")
## call function

png(paste(inpath, plotname, sep = "/"), width = 1024*3, height = 768*3)
strip(x = t, 
      date = datetime, 
      cond = plot, 
      fun = mean,
      arrange = "long",
      main = "Temperature",
      colour = colList$colPrec)
dev.off()
